package com.it2297.view;

import javax.swing.JPanel;
import javax.swing.JButton;

import com.it2297.controller.NeedyController;
import com.it2297.controller.ProductController;
import com.it2297.main.UserApp;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.factories.FormFactory;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JComboBox;
import javax.swing.JSpinner;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.DefaultComboBoxModel;

public class NeedyProfileView extends JPanel {
	private final NeedyController pc = new NeedyController(this);
	private final JLabel lblNric = new JLabel("NRIC ");
	private final JLabel lblName = new JLabel("Name");
	private final JLabel lblPhone = new JLabel("Phone");
	private final JLabel lblGender = new JLabel("Gender");
	private final JTextField NameTxt = new JTextField();
	private final JTextField PhoneTxt = new JTextField();
	private final JLabel lblAddress = new JLabel("Address");
	private final JTextArea AddressTxtPane = new JTextArea();
	private final JLabel lblEmail = new JLabel("Email");
	private final JTextField EmailTxt = new JTextField();
	private final JLabel lblRace = new JLabel("Race");
	private final JLabel lblNewLabel_5 = new JLabel("Your Profile");
	private final JTextField NricTxt = new JTextField();
	private final JLabel lblDateOfBirth = new JLabel("Date Of Birth");
	private final JLabel lblStatus = new JLabel("Status");
	private final JLabel lblCountryOfBirth = new JLabel("Country Of Birth");
	private final JTextField StatusTxt = new JTextField();
	private final JLabel lblHouseholdIncome = new JLabel("HouseHold Income");
	private final JLabel lblNewLabel_10 = new JLabel("Number Of Dependent");
	private final JLabel lblNewLabel_11 = new JLabel("New label");
	private final JLabel lblNewLabel_12 = new JLabel("Family Size");
	private final JTextField HouseholdIncomeTxt = new JTextField();
	private final JTextField NumOfDependentTxt = new JTextField();
	private final JTextField FamilySizeTxt = new JTextField();
	private final JTextField pwdTxt = new JTextField();
	private final JLabel lblPassword = new JLabel("Password");
	private final JTextField DateTxt = new JTextField();
	private final JTextField RaceTxt = new JTextField();
	private final JTextField countryTxt = new JTextField();
	private final JTextField genderTxt = new JTextField();
	private final JButton btnView = new JButton("View");

	/**
	 * Create the panel.
	 */
	public NeedyProfileView() {
		genderTxt.setEditable(false);
		genderTxt.setBounds(309, 281, 171, 23);
		genderTxt.setColumns(10);
		//genderTxt.setText(UserApp.getCurrentUser().getGender());
		countryTxt.setEditable(false);
		countryTxt.setBounds(309, 461, 171, 23);
		countryTxt.setColumns(10);
		//countryTxt.setText(UserApp.getCurrentUser().getCountryOfBirth());
		RaceTxt.setEditable(false);
		RaceTxt.setBounds(309, 352, 171, 23);
		RaceTxt.setColumns(10);
		//RaceTxt.setText(UserApp.getCurrentUser().getEthnic());
		DateTxt.setEnabled(true);
		DateTxt.setEditable(false);
		DateTxt.setBounds(309, 387, 171, 30);
		DateTxt.setColumns(10);
		//DateTxt.setText(UserApp.getCurrentUser().getDob());
		pwdTxt.setEditable(false);
		pwdTxt.setBounds(309, 238, 171, 23);
		pwdTxt.setColumns(10);
		//pwdTxt.setText(UserApp.getCurrentUser().getPassword());
		FamilySizeTxt.setEditable(false);
		FamilySizeTxt.setBounds(309, 558, 171, 23);
		FamilySizeTxt.setColumns(10);
		//FamilySizeTxt.setText(UserApp.getCurrentUser().getFamilySize());
		NumOfDependentTxt.setEditable(false);
		NumOfDependentTxt.setBounds(309, 523, 171, 24);
		NumOfDependentTxt.setColumns(10);
		//NumOfDependentTxt.setText(UserApp.getCurrentUser().getNumOfDependent());
		HouseholdIncomeTxt.setEditable(false);
		HouseholdIncomeTxt.setBounds(309, 492, 171, 20);
		HouseholdIncomeTxt.setColumns(10);
		//HouseholdIncomeTxt.setText(UserApp.getCurrentUser().getHouseHoldIncome());
		StatusTxt.setEditable(false);
		StatusTxt.setBounds(309, 428, 171, 23);
		StatusTxt.setColumns(10);
		//StatusTxt.setText(UserApp.getCurrentUser().getStatus());
		NricTxt.setEditable(false);
		NricTxt.setBounds(309, 36, 171, 26);
		NricTxt.setColumns(10);
		NricTxt.setText(UserApp.getCurrentUser().getNric());
		EmailTxt.setEditable(false);
		EmailTxt.setBounds(309, 317, 171, 23);
		EmailTxt.setColumns(10);
		//EmailTxt.setText(UserApp.getCurrentUser().getEmail());
		PhoneTxt.setEditable(false);
		PhoneTxt.setBounds(309, 204, 171, 23);
		PhoneTxt.setColumns(10);
		//PhoneTxt.setText(UserApp.getCurrentUser().getPhone());
		//AddressTxtPane.setText(UserApp.getCurrentUser().getAddress());
		setLayout(null);
		NameTxt.setEditable(false);
		NameTxt.setBounds(309, 73, 171, 32);
		
		NameTxt.setColumns(10);
		NameTxt.setText(UserApp.getCurrentUser().getName());
		this.setSize(1000,700);

		initGUI();
	}
	
	
	public String getNeedyNric(){
	return NricTxt.getText().toString();
	}
	
	public String getNeedyName(){
		return NameTxt.getText();
	}
	
	public void setNeedyName(String name){
		NameTxt.setText(name);
	}
	
	public String getNeedyAddress(){
		return AddressTxtPane.getText();
	}
	
	public void setNeedyAddress(String address){
		AddressTxtPane.setText(address);
	}
	
	public String getNeedyPhone(){
		return PhoneTxt.getText();
	}
	
	public void setNeedyPhone(String phone){
	       PhoneTxt.setText(phone);
	}
	
	public String getNeedyPassword(){
	return pwdTxt.getText();
	}
	
	//password
	public void setNeedyPassword(String password){
	       pwdTxt.setText(password);
	}
	
	
	
	public String getNeedyGender(){
		return genderTxt.getText();
	}
	
	public void setNeedyGender(String gender){
		genderTxt.setText(gender);
	}
	
	
	
	public String getNeedyEmail(){
		return EmailTxt.getText();
	}
	
	public void setNeedyEmail(String email){
		EmailTxt.setText(email);
	}
	
	public String getNeedyEthnic(){
		return RaceTxt.getText();
	}
	
	public void setNeedyEthnic(String ethnic){
		RaceTxt.setText(ethnic);
	}

	
	 public Date getNeedyDob(){
		 DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); 
		 
		 Date date = null;
		try {
			date = (Date)formatter.parse(DateTxt.getText());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println(date);
		 return date;
		 
	  }

	
	 public void setNeedyDob(Date dob){
		 DateFormat df = new SimpleDateFormat("MM-dd-yyyy HH:mm:ss");
		 String reportDate = df.format(dob);
		 DateTxt.setText(reportDate);
		 
	 }
	 
	
	public String getNeedyStatus(){
		return StatusTxt.getText();
	}
	
	public void setNeedyStatus(String status){
		StatusTxt.setText(status);
	}
	
	//
	public String getNeedyCountryOfBirth(){
		return countryTxt.getText();
	}
	
	public void setNeedyCountryOfBirth(String country){
		countryTxt.setText(country);
	}
	
	public double getNeedyHouseHoldIncome(){
		return Double.parseDouble(HouseholdIncomeTxt.getText());
	}
	
	//needy 
	
	public void setNeedyHouseHoldIncome(double householdincome){
		HouseholdIncomeTxt.setText(Double.toString(householdincome));
	}
	
	public int getNeedyNumOfDependent(){
		return Integer.parseInt(NumOfDependentTxt.getText()) ;
	}
	
	public void setNeedyNumOfIndependent(int numofindependent){
		NumOfDependentTxt.setText(Integer.toString(numofindependent));
	}
	
	public int getNeedyFamilySize(){
		return Integer.parseInt(FamilySizeTxt.getText());
	}
	
	public void setNeedyFamilySize(int familysize){
		FamilySizeTxt.setText(Integer.toString(familysize));
	}
	
	private void initGUI() {
		setLayout(null);
		lblNric.setFont(new Font("Arial", Font.PLAIN, 19));
		lblNric.setBounds(221, 32, 57, 23);
		
		add(lblNric);
		lblName.setFont(new Font("Arial", Font.PLAIN, 19));
		lblName.setBounds(221, 75, 51, 23);
		
		add(lblName);
		
		add(NameTxt);
		lblPhone.setFont(new Font("Arial", Font.PLAIN, 19));
		lblPhone.setBounds(209, 193, 69, 38);
		
		add(lblPhone);
		lblGender.setFont(new Font("Arial", Font.PLAIN, 19));
		lblGender.setBounds(189, 264, 72, 49);
		
		add(lblGender);
		
		add(PhoneTxt);
		lblAddress.setFont(new Font("Arial", Font.PLAIN, 19));
		lblAddress.setBounds(203, 132, 72, 38);
		
		add(lblAddress);
		AddressTxtPane.setEnabled(true);
		AddressTxtPane.setEditable(false);
		AddressTxtPane.setWrapStyleWord(true);
		AddressTxtPane.setLineWrap(true);
		AddressTxtPane.setBounds(309, 116, 171, 70);
		
		add(AddressTxtPane);
		lblEmail.setFont(new Font("Arial", Font.PLAIN, 19));
		lblEmail.setBounds(209, 306, 69, 38);
		
		add(lblEmail);
		
		add(EmailTxt);
		lblRace.setFont(new Font("Arial", Font.PLAIN, 19));
		lblRace.setBounds(209, 343, 69, 32);
		
		add(lblRace);
		lblNewLabel_5.setFont(new Font("Arial", Font.PLAIN, 19));
		lblNewLabel_5.setBounds(273, 2, 131, 23);
		
		add(lblNewLabel_5);
		
		add(NricTxt);
		lblDateOfBirth.setFont(new Font("Arial", Font.PLAIN, 19));
		lblDateOfBirth.setBounds(177, 387, 115, 23);
		
		add(lblDateOfBirth);
		lblStatus.setFont(new Font("Arial", Font.PLAIN, 19));
		lblStatus.setBounds(221, 429, 58, 14);
		
		add(lblStatus);
		lblCountryOfBirth.setFont(new Font("Arial", Font.PLAIN, 19));
		lblCountryOfBirth.setBounds(140, 454, 147, 23);
		
		add(lblCountryOfBirth);
		
		add(StatusTxt);
		lblHouseholdIncome.setFont(new Font("Arial", Font.PLAIN, 19));
		lblHouseholdIncome.setBounds(128, 488, 164, 23);
		
		add(lblHouseholdIncome);
		lblNewLabel_10.setFont(new Font("Arial", Font.PLAIN, 19));
		lblNewLabel_10.setBounds(93, 522, 206, 23);
		
		add(lblNewLabel_10);
		lblNewLabel_11.setBounds(118, 705, 46, 14);
		
		add(lblNewLabel_11);
		lblNewLabel_12.setFont(new Font("Arial", Font.PLAIN, 19));
		lblNewLabel_12.setBounds(163, 556, 115, 23);
		
		add(lblNewLabel_12);
		
		add(HouseholdIncomeTxt);
		
		add(NumOfDependentTxt);
		
		add(FamilySizeTxt);
		
		add(pwdTxt);
		lblPassword.setFont(new Font("Arial", Font.PLAIN, 19));
		lblPassword.setBounds(189, 242, 85, 14);
		
		add(lblPassword);
		
		add(DateTxt);
		
		add(RaceTxt);
		
		add(countryTxt);
		
		add(genderTxt);
		
		btnView.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {			
				String nric = NricTxt.getText();
               	pc.getProfileDetail(nric);
				
				//
				
				
			}
		});
		
		
		
		btnView.setBounds(489, 35, 89, 23);
		
		add(btnView);
	}
}
